$(document).ready(function () {
    $("#tijiao").click(function () {
        let id = $("#zhanghao").val();
        let uname = $("#xingming").val();
        let pwd = $("#mima").val();
        let age = $("#nianling").val();
        let a = $("input[name='sex']:checked").val();
        let sex = "";
        switch (a) {
            case "1":
                sex = "男";
                break;
            case "0":
                sex = "女";
                break;
            default:
                alert("未选择性别！");
                return;
        }
        let b = $("input[name='admin']:checked").val();
        let admin = "";
        switch (b) {
            case "1":
                admin = "true";
                break;
            case "0":
                admin = "false";
                break;
            default:
                alert("未选择是否为管理员！");
                return;
        }
        setValue(id, uname, pwd, age, sex, admin);
    })
})

function setValue(id, uname, pwd, age, sex, admin) {
    let url = "users?method=updateUsers&id=" + id +
        "&uname=" + uname + "&pwd=" + pwd +
        "&age=" + age + "&sex=" + sex + "&admin=" + admin;
    $.get(url, function (data, status) {
        let errcode = data["errcode"];
        let errmsg = data["errmsg"];
        if (errcode)
            alert("[Error]" + errmsg);
        else
            alert("数据更新成功！");
    })
}